package com.yutel.pinyin;

public class JsonTest {

	public static void main(String[] args) {
		JsonTest jt = new JsonTest();
		String pp = "anhui_order:[lib:anhuiorder,authurl:61.191.45.143:80/aaa/,openurl:61.191.45.143:80/aaa/,version:4];HD:[hd_all:http://epg.funhd.cn/epg/android/anhui-live-groups-categories.xml,hd_fastlive:http://epg.funhd.cn/epg/android/anhui-all-liveTVs.xml];SD:[sd_all:http://epg.funhd.cn/epg/anhui/anhui-live-groups-categories.xml,sd_fastlive:http://epg.funhd.cn/epg/anhui/anhui-all-liveTVs.xml]";
		System.out.println(jt.getChannel(true, pp));
		System.out.println(jt.getChannel(false, pp));
		System.out.println(jt.getChannel(true, pp));
		System.out.println(jt.getChannel(false, pp));
	}

	private String getChannel(boolean all, String settings) {
		if (settings == null) {
			return null;
		}
		boolean hd = true;
		int hdb = settings.indexOf("HD:");
		if (hdb < 0) {
			hd = false;
		}
		String startS;
		if (hd && all) {
			startS = "hd_all:";
		} else if (hd && !all) {
			startS = "hd_fastlive:";
		} else if (!hd && all) {
			startS = "sd_all:";
		} else {
			startS = "sd_fastlive:";
		}
		int start = settings.indexOf(startS) + startS.length();
		if (start < startS.length()) {
			return null;
		}
		int end = settings.indexOf(".xml", start) + 4;
		String res = settings.substring(start, end);
		return res;
	}
}
